//
//  CUser.h
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-13.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MapKit/MKMapView.h>
#import "CNetWorkRequest.h"
#import "CDBManager.h"
#import "CProduct.h"
#import "CFriend.h"
#import "Message.h"
#import "CLocator.h"
#import "GTMBase64.h"

@class CDBManager;
@class CKey;
@class CLocator;
@class CAddrInfo;
@class CProduct;
@class CLike;

#define User_Properties_Num 23

typedef enum {Visitor, Logined, Leave, None}UType;
typedef enum {Register=1, Login, Logout, FindPwd, GLastestP, GNearestP, GBestP, GSearchP, GFavoriteP, GUploadP, FavoriteP, UploadImage, UploadP, GetFrds, ChangeSwitch, UploadIcon}UCommand;

@interface CUser : NSObject <NetWorkRequestDelegate>

@property (nonatomic, retain) NSString * U_City;
@property (nonatomic, retain) NSString * U_Nick;
@property (nonatomic, retain) NSString * U_Pas;
@property (nonatomic, retain) NSString * U_Token;
@property (nonatomic, retain) NSString * U_Session;
@property (nonatomic, retain) NSString * U_UrlIcon;
@property (nonatomic, retain) NSString * U_Name;
@property (nonatomic, retain) NSString * U_Mail;
@property (nonatomic, retain) NSString * U_CurCity;

@property (nonatomic, retain) NSString * U_Icon;

@property (nonatomic, retain) NSNumber * U_AID;
@property (nonatomic, retain) NSNumber * U_LogIn;
@property (nonatomic, retain) NSNumber * U_QqOn;
@property (nonatomic, retain) NSNumber * U_SinaOn;
@property (nonatomic, retain) NSNumber * U_RenrenOn;
@property (nonatomic, retain) NSNumber * U_DisedOn;
@property (nonatomic, retain) NSNumber * U_FpubOn;
@property (nonatomic, retain) NSNumber * U_OsOn;
@property (nonatomic, retain) NSNumber * U_FrdNum;
@property (nonatomic, retain) NSNumber * U_PdtNum;
@property (nonatomic, retain) NSNumber * U_DisNum;

@property (nonatomic, retain) NSString * m_RootPath;
@property (nonatomic, retain) NSString * m_FriendPath;
@property (nonatomic, retain) NSString * m_FavoritePath;
@property (nonatomic, retain) NSString * m_FriendTable;
@property (nonatomic, retain) NSString * m_FavoriteTable;
@property (nonatomic, retain) NSString * m_UploadPath;
@property (nonatomic, retain) NSString * m_UploadTable;
@property (nonatomic, retain) NSString * m_DraftPath;

@property (nonatomic, assign) CAddrInfo              *m_AddrInfo;
@property (nonatomic, assign) CLLocationCoordinate2D m_SelfPosition;

//action
@property (nonatomic, assign) BOOL          m_IsIconLoad;
@property (nonatomic, retain) CTask         *m_IconOpID;
@property (nonatomic, retain) UIImageView   *m_IconView;

@property (nonatomic, assign) UCommand  m_UCommand;
@property (nonatomic, assign) SEL       m_Action;
@property (nonatomic, retain) id        m_Target;

//数据请求
@property (nonatomic, assign)  CNetWorkRequest  *m_NetRequest;          //heartbeat

//临时信息
@property (nonatomic, assign) UType m_UType;

//favorites
@property (nonatomic, assign) CAscCounter    *m_FavoriteCnt;
@property (nonatomic, assign) CAscCounter    *m_NetFavosCnt;

//friends
@property (nonatomic, assign) CAscCounter    *m_FriendCnt;
@property (nonatomic, assign) CAscCounter    *m_NetFrdCnt;

//timer
@property (nonatomic, assign) NSTimer        *m_HeartBeat;

+(CUser*)DefaultUser;
+(void)DestroyUser;

+(int)CreateUserTable:(NSString*)tablename;
+(NSArray*)GetLimitUsers:(NSString*)where Offset:(int)offset Limit:(int)limit;
+(NSInteger)GetUserCount:(NSString*)where;
+(int)UpadteUserInfo:(NSString*)where Keys:(NSArray*)keys;
+(int)RemoveUser:(NSString*)where;

//heartbeat
-(void)StartHeartBeat;
-(void)StopHeartBeat;
-(void)SendHeartBeat;
-(void)ReceiveHeartBeat:(NSData*)notification;

-(void)SetUserWithArr:(NSArray*)arr;
-(void)ResetUser;
-(int)SaveUser;
-(int)SaveIcon:(NSData*)data;
-(NSData*)GetUserIcon;
-(int)DownloadUserIcon;
-(void)GetCurUser;
//get user's favorites from native
-(NSArray*)GetCurUserFavos;
//get user's favorites from server
-(void)GetCurUserFavosFromSrv;
-(NSArray*)GetCurUserFrds;
//get user's friends from server
-(void)GetCurUserFrdsFromSrv;

//user operation
-(BOOL)IsEmailRight:(NSString*)email;
-(unichar)IsLoginIDRight:(NSString*)strid;
-(int)CheckUserRegInput:(NSString*)name Mail:(NSString*)mail PasWd:(NSString*)paswd;
-(int)CheckUserLoginInput:(NSString*)name Mail:(NSString*)mail PasWd:(NSString*)paswd;
-(NSArray*)CheckIsNativeUser:(NSString*)key PasWd:(NSString*)paswd;
-(int)UserRegister:(NSString*)name PassWord:(NSString*)pwd EMail:(NSString*)email City:(NSString*)city Nick:(NSString*)nick;
-(int)UserUploadIcon:(NSData*)data;
-(int)UserLogin:(NSString*)name PassWord:(NSString*)pwd EMail:(NSString*)email City:(NSString*)city;
-(int)UserLogout;
-(int)UserFindPwd:(NSString*)email;
-(void)GetServerFindPwdResult:(NSDictionary*)data;
-(int)UserChangeSwitchValue:(NSString*)index Value:(int)value;
-(void)ChangeSwitchResponse:(NSDictionary*)dic;

//client request
//get products from server
-(CTask*)GetProductsFromServer:(NSString*)data Url:(NSString*)url Command:(UCommand)command Object:(id)object; 
-(NSError*)UserFavoriteProduct:(NSString*)data;
//user register successful
-(void)GetServerRegisterResult:(NSDictionary*)data;
//user login successful
-(void)GetServerLoginResult:(NSDictionary*)data;
//use logout successful
-(void)GetServerLogoutResult:(NSDictionary*)data;
//upload a new product
-(void)UserUploadNewProductPic:(int)width Height:(int)height Data:(NSData*)data;
-(void)UserUploadNewProduct:(NSString*)data Url:(NSString*)url Command:(UCommand)command;

//save upload
-(void)SaveUpload:(CProduct*)product;

//save favorite
-(int)SaveFavorite:(CProduct*)product;

@end

